from bcat.util.str import Str
import os

class Log(object):
    class Level(object):
        def __init__(self, v):
            self.__v = v

        def value(self):
            return self.__v

        def __eq__(self, other):
            return self.__v == other.__v

        @staticmethod
        def debug():
            return Log.Level(1)
        @staticmethod
        def trace():
            return Log.Level(2)
        @staticmethod
        def notice():
            return Log.Level(3)
        @staticmethod
        def warning():
            return Log.Level(4)
        @staticmethod
        def error():
            return Log.Level(5)
        @staticmethod
        def fatal():
            return Log.Level(6)

        def __str__(self):
            var = { 
                1:"level.debug",
                2:"level.trace",
                3:"level.notice",
                4:"level.warning",
                5:"level.error",
                6:"level.fatal",
            }
            if self.__v in var:
                return var[self.__v]
            else:
                return "unknow level"


    class Builder(object):
        def __init__(self, dir_name, file_name, level, enable_date_roll, file_size_roll):
            self.__dir_name = dir_name
            self.__file_name = file_name
            self.__level = level
            self.__enable_date_roll = enable_date_roll
            self.__file_size_roll = file_size_roll

        def directory(self, dir_name):
            if not Str(dir_name).is_empty_or_space():
                if not os.path.exists(dir_name):
                    os.mkdir(dir_name)
                self.__dir_name =  dir_name
            return self

        def file_name(self, file_name):
            if not Str(file_name).is_empty_or_space():
                self.__file_name = file_name
            return self

        def level(self, level):
            if self.__level != level:
                self.__level = level
            return self

        def enable_date_roll(self):
            self.__enable_date_roll = True
            return self
        def disable_date_roll(self):
            self.__enable_date_roll = False
            return self

        def file_size_roll(self, nsize):
            if nsize > 0:
                self.__file_size_roll = nsize
            return self

        def make(self): 
            raise NotImplementedError()

        def __str__(self):
            raise NotImplementedError()


    def dir_name(self):
        raise NotImplementedError()
    def file_name(self):
        raise NotImplementedError()
    def level(self, level):
        raise NotImplementedError()
        
    def date_roll_enabled(self):
        raise NotImplementedError()
    def roll_size(self):
        raise NotImplementedError()

    def path(self):
        raise NotImplementedError()


    
    def set_dir_name(self, dir_name):
        raise NotImplementedError()
    def set_file_name(self, file_name):
        raise NotImplementedError()

    def set_level(self, level):
        raise NotImplementedError()

    def enable_date_rolling(self):
        raise NotImplementedError()

    def disable_date_rolling(self):
        raise NotImplementedError()

    def set_file_rolling_size(self, nsize):
        raise NotImplementedError()
        

    def destroy(self):
        raise NotImplementedError()

    def __del__(self):
        self.destroy()


    def __str__(self):
        return "Log"
        

#log = Log.Builder().directory("log")

#print(Log.Level.debug())
